<template>
	<view>
		<!-- 支付 -->
		<web-view id="webviewId"></web-view>
	</view>
</template>

<script>
	import myRequest from '@/api/index.js'
	import md5 from '../../../common/md5.js'
	import dokey from '../../../common/dokey.js'
	export default {
		data() {
			return {
				payCode: '',
				payId: '',
				baseUrl: '',
				ispay: 0
			}
		},
		onLoad(option) {
			this.payCode = option.payCode
			this.payId = option.payId
			this.getBaseUrl()
		},
		onShow() {
			if (this.ispay == 1) {
				uni.navigateBack({
					delta: 1
				})
			}
		},
		methods: {
			show_webView() {
				let that = this
				var nwating = plus.nativeUI.showWaiting();
				var w = plus.webview.create(this.baseUrl, 'webviewId', {
					height: '93%'
				}, {
					preload: 'preload webview'
				});
				w.addEventListener('loaded', function() {
					that.ispay = 1
					nwating.close();
				}, false);
			},
			getBaseUrl() {
				let config = {}
				config.token = uni.getStorageSync('token')
				config.pay_code = this.payCode
				config.pay_id = this.payId
				config.v = '1.0'
				// let sortData = {} // 排序后的对象
				// Object.keys(config).sort().map(key => {
				// 	sortData[key] = config[key]
				// })
				var secretdate = dokey.secretdate()
				// var secretedOne = md5(JSON.stringify(sortData) + dokey.getkey() + secretdate)
				var secretedOne = md5(dokey.getkey() + secretdate)
				var secreted = md5(secretedOne) // 签名

				let url = encodeURI('https://api.loveworldzh.com/api/pay/quickpay?auth_timestramp=' + secretdate +
					'&auth_sign=' + secreted + '&token=' + config.token + '&pay_code=' + config.pay_code + '&pay_id=' +
					config.pay_id)
				this.baseUrl = url

				this.show_webView()
			}
		}
	}
</script>

<style>
</style>
